package com.ztools.pc.controller.information;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ztools.common.model.pc.information.Grade;
import com.ztools.common.util.common.PageUtil;
import com.ztools.common.util.common.Result;
import com.ztools.pc.service.information.GradeService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author:一口香菜
 * @Date: 2023/3/12  14:52
 * @Version 1.0
 */
@RestController
@RequestMapping("/information/grade")
public class GradeController {

    @Resource
    private GradeService gradeService;

    @RequestMapping("/list")
    public Result findList(@RequestBody PageUtil<Grade> pageUtil) {
        Page<Grade> list = gradeService.findList(pageUtil);
        return list != null ? Result.success("查询成功").data(list) : Result.error();
    }

    @RequestMapping("findByObject")
    public Result findByObject(@RequestBody Grade grade) {
        List<Grade> list = gradeService.findByObject(grade);
        return list != null ? Result.success("查询成功").data(list) : Result.error();
    }

    @RequestMapping("/add")
    public Result add(@RequestBody Grade grade) {
        boolean b = gradeService.save(grade);
        return b ? Result.success("添加成功") : Result.error("添加失败");
    }

    @RequestMapping("/update")
    public Result update(@RequestBody Grade grade) {
        boolean b = gradeService.update(grade);
        return b ? Result.success("添加成功") : Result.error("添加失败");
    }

}
